<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<script type="text/javascript" charset="utf-8">
  function validate(){
      var pwd1 = $("#password1").val();
      var pwd2 =$("#password2").val();
      if(pwd1!=pwd2){
          $("#password2").css("color","red");
          $("#warntxt2").text("两次密码不一致！");
          $("button").attr("disabled","disabled");
          return ;
      }
  }

 var http_request;
  function createRequest(){
      if(window.XMLHttpRequest){
          http_request = new XMLHttpRequest();
      }else{
          http_request = new ActiveXObject("Microsoft.XMLHTTP");
      }
  }

  function checkAdmin(addusername){
      var url='checkAdmin?addusername='+addusername.value;
      createRequest();
      http_request.onreadystatechange = getResult; //调用回调函数
      http_request.open('POST', url, true); //创建与服务器的连接
      http_request.send(); //向服务器发送请求
  }

  function getResult(){
      if(http_request.readyState==4){
          if(http_request.status==200){
            document.getElementById("warntxt1").innerHTML=http_request.responseText;
            document.getElementById("warntxt1").style.display="block";
          }else{
              alert("请求有误！");
          }
      }
  }
</script>
<div class="layui-body">
    <div style="padding: 15px">
        <div class="layui-card" >
            <div class="layui-card-header" style="background-color: #FF5722">添加新管理员</div>
            <div class="layui-card-body">
                <form class="layui-form " action="/AddAdmin" name="addAdminForm" method="post">
                    <%--账号--%>
                    <div class="layui-form-item">
                        <label class="layui-form-label"
                               style="font-size: 20px; color: #5F6FC9;">账号</label>
                        <div class="layui-input-inline">
                            <input type="text" name="addusername" required lay-verify="required" placeholder="请输入账号"
                                   autocomplete="off" class="layui-input" oninvalid="setCustomValidity('账号不能为空！')" onblur="checkAdmin(this)">
                        </div>
                        <div class="layui-form-mid layui-word-aux" id="warntxt1"></div>
                    </div>
                    <%--密码--%>
                    <div class="layui-form-item">
                        <label class="layui-form-label"
                               style="font-size: 20px; color: #5f6fc9;">密码</label>
                        <div class="layui-input-inline">
                            <input type="password" name="addpassword1" id="password1" required lay-verify="required" placeholder="请输密码"
                                   autocomplete="off" class="layui-input" oninvalid="setCustomValidity('密码不能为空！')">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"
                               style="font-size: 20px; color: #5f6fc9;">确认密码</label>
                        <div class="layui-input-inline">
                            <input type="password" name="addpassword2" id="password2" required lay-verify="required" placeholder="请确认密码"
                                   autocomplete="off" class="layui-input" oninvalid="setCustomValidity('请确认密码！')">
                        </div>
                        <div class="layui-form-mid layui-word-aux" id="warntxt2"></div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-submit lay-filter="formDemo" type="submit" onclick="validate()">注册</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>